﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace TI_EntityLib
{
    public class DayLog
    {
        const string defFileName = "DayLog.xml";

        private static string GetFolderConfig()
        {
            return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\TI_DATA\";
        }

        public static string GetConfigFileName()
        {
            if (File.Exists(GetFolderConfig() + defFileName))
                return GetFolderConfig() + defFileName;

            throw new Exception("не найден файл " + GetFolderConfig() + defFileName);
        }

        public static void SaveError(TiException exception)
        { 
        }

        public static DayLog ReadConfig()
        {
            string filename = GetConfigFileName();

            XmlSerializer serializer = new XmlSerializer(typeof(DayLog));
            DayLog result = null;
            using (FileStream fs = new FileStream(filename, FileMode.Open))
            {
                result = (DayLog)serializer.Deserialize(fs);
                fs.Close();
            }
            return result;

        }

        public void WriteConfig()
        {
            string filename = GetConfigFileName();
            XmlSerializer mySerializer = new
            XmlSerializer(typeof(DayLog));
            using (StreamWriter myWriter = new StreamWriter(filename))
            {
                mySerializer.Serialize(myWriter, this);
                myWriter.Close();
            }
        }

        public static DayLog DefautCreateConfig()
        {
            DayLog c = new DayLog();
            c.WriteConfig();
            return c;
        }


        TransportLog TransportLog { get; set; }
        
    }

    public class TransportLog {
        //Обработано файлов
        public int XmlFileWrited { get; set; }

    }  
}
